function ajax(user: any) {
  new Promise((resolve, reject) => {
    let xhr = new XMLHttpRequest();
    xhr.open('GET', 'ss');
    xhr.send();
    xhr.onload = function () {
      if (this.status == 200) {
        resolve(JSON.parse(this.response));
      } else if (this.status == 404) {
        reject(new Error('用户不存在'));
      } else {
        reject('加载失败');
      }
    };
  });
}
function render(users: Array<Promise<unknown>>) {
  users.reduce((promise, user) => {
    return promise
      .then((_) => {
        return ajax(user);
      })
      .then((_) => {
        view(user);
      });
  }, Promise.resolve());
}

function view(user: any) {
  return new Promise((resolve) => {
    console.log(user);
    let h2 = document.createElement('h2')
    h2.innerHTML = user
    document.body.appendChild(h2)
    resolve('')
  });
}
